package com.rxz.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.serializer.StringRedisSerializer;

//@Configuration
//public class RedisMessageConfig {
//
//    @Autowired
//    private MessageListenerAdapter messageListenerAdapter;
//
//    @Autowired
//    private ChannelTopic channelTopic;
//
//    @Bean
//    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
//        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
//        container.setConnectionFactory(connectionFactory);
//        container.addMessageListener(messageListenerAdapter, channelTopic);
//        return container;
//    }
//
//    @Bean
//    public MessageListenerAdapter messageListenerAdapter() {
//        return new MessageListenerAdapter(new MessageReceiver());
//    }
//
//    @Bean
//    public ChannelTopic channelTopic() {
//        return new ChannelTopic("your-channel");
//    }
//
//    // 自定义的消息接收器类
//    public static class MessageReceiver implements MessageListener {
//        @Override
//        public void onMessage(Message message, byte[] pattern) {
//            System.out.println("收到消息：" + new String(message.getBody()));
//        }
//    }
//}

